package com.android.kotlincoroutinemvvmdemo.view
import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Path
import android.util.AttributeSet
import com.android.kotlincoroutinemvvmdemo.R

/*
* ClipView9
* */
class ClipView9 @JvmOverloads constructor(
    context: Context,
    attributeSet: AttributeSet? = null
) : BaseView(context, attributeSet) {

    private val mPaint0 by lazy {
        Paint().apply {
            isAntiAlias = true
            isDither = true
            color = context.resources.getColor(R.color.color_F3236D)
        }
    }

    private val mPath0 by lazy {
        Path()
    }

    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)
        setBackgroundColor(context.resources.getColor(R.color.color_F3F3F3))
        canvas?.apply {
            val cx = mWidth.toFloat() / 2
            val cy = mHeight.toFloat() / 2
            save()
            translate(cx, cy)

            mPath0.apply {
                reset()
//                addCircle(
//                    0F,
//                    -cy,
//                    cx,
//                    Path.Direction.CCW
//                )
//                addCircle(
//                    -cx ,
//                    0F,
//                    cx,
//                    Path.Direction.CCW
//                )
                addCircle(
                    cx,
                    0F,
                    cx,
                    Path.Direction.CCW
                )
                addCircle(
                    0F,
                    cy ,
                    cx,
                    Path.Direction.CCW
                )
            }
            drawPath(mPath0, mPaint0)

            restore()
        }
    }
}